package com.cecsmsserve.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cecsmsserve.entity.HealthRecordType;
import com.cecsmsserve.mapper.HealthRecordTypeMapper;
import com.cecsmsserve.service.HealthRecordTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class HealthRecordTypeServiceImpl extends ServiceImpl<HealthRecordTypeMapper, HealthRecordType> implements HealthRecordTypeService {

    @Autowired
    private HealthRecordTypeMapper healthRecordTypeMapper;

    @Override
    public List<HealthRecordType> getActiveTypes() {
        return healthRecordTypeMapper.getActiveTypes();
    }

    @Override
    public boolean addType(HealthRecordType healthRecordType) {
        if (healthRecordType == null) {
            return false;
        }
        return save(healthRecordType);
    }

    @Override
    public boolean updateType(HealthRecordType healthRecordType) {
        if (healthRecordType == null || healthRecordType.getId() == null) {
            return false;
        }
        return updateById(healthRecordType);
    }

    @Override
    public boolean disableType(Integer id) {
        if (id == null) {
            return false;
        }
        HealthRecordType type = getById(id);
        if (type == null) {
            return false;
        }
        type.setStatus(false);
        return updateById(type);
    }

    @Override
    public boolean enableType(Integer id) {
        if (id == null) {
            return false;
        }
        HealthRecordType type = getById(id);
        if (type == null) {
            return false;
        }
        type.setStatus(true);
        return updateById(type);
    }
} 